package com.binyouwei.udp_lib;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 宾有为
 * @date 2024/6/12 10:27
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * @describe：
 **/
public class SingleThreads {

    private SingleThreads(){}

    private static final class InstanceHolder {
        private static final SingleThreads INSTANCE = new SingleThreads();
    }

    public static SingleThreads getInstance() {
        return InstanceHolder.INSTANCE;
    }

    ScheduledThreadPoolExecutor singleThreads = new ScheduledThreadPoolExecutor(8);

    /**
     * 一次性任务
     * @param runnable
     */
    public void execute(Runnable runnable) {
        singleThreads.execute(runnable);
    }

    /**
     * 延迟的一次性任务
     * @param runnable
     * @param delay
     * @param unit
     */
    public void schedule(Runnable runnable, long delay, TimeUnit unit) {
        singleThreads.schedule(runnable, delay, unit);
    }


}
